import 'package:flutter/material.dart';

import 'data_conversion.dart';

class YText extends StatelessWidget {
  final double fontSize;
  TextStyle? style;
  final dynamic text;
  final FontWeight? fontWeight;
  final TextAlign textAlign;
  final TextOverflow? overflow;
  final Color? color;
  final int maxLines;
  TextDecorationConfig? decorationConfig; //下划线配置
  YText({
    super.key,
    this.fontSize = 15,
    this.style,
    this.text,
    this.fontWeight,
    this.textAlign = TextAlign.center,
    this.overflow = TextOverflow.ellipsis,
    this.color,
    this.maxLines = 1,
    this.decorationConfig,
  });

  @override
  Widget build(BuildContext context) {
    return Text(
      yToString(text),
      textAlign: textAlign,
      overflow: overflow,
      style: style ??= TextStyle(
        fontSize: fontSize,
        fontWeight: fontWeight,
        color: color,
        decoration: decorationConfig?.decoration,
        decorationColor: decorationConfig?.decorationColor,
        decorationStyle: decorationConfig?.decorationStyle,
        decorationThickness: decorationConfig?.decorationThickness,
      ),
      maxLines: maxLines,
    );
  }
}

class TextDecorationConfig {
  TextDecoration? decoration;
  Color? decorationColor;
  double? decorationThickness;
  TextDecorationStyle? decorationStyle;

  TextDecorationConfig({
    this.decoration = TextDecoration.none,
    this.decorationColor = Colors.blue,
    this.decorationThickness = 2.0,
    this.decorationStyle = TextDecorationStyle.solid,
  });
}
